package vn.ttpcode.com.sample.listview;

import java.util.ArrayList;

import vn.ttpcode.com.sample.R;
import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ListView;

public class ListViewAct extends Activity{
	
	private static final String TAG = "ttpcode";
	private ListView lvWrapper;
	private ListViewAdapter adapter;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		setContentView(R.layout.listview_act);
		
		adapter = new ListViewAdapter(this, virtualList());
		lvWrapper = (ListView) findViewById(R.id.lvWrapper);
		
		lvWrapper.setAdapter(adapter);
		lvWrapper.setOnScrollListener(adapter);
		
		lvWrapper.setOnItemClickListener(new OnItemClickListener() {

			@Override
			public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
					long arg3) {
				// TODO Auto-generated method stub
				Log.e(TAG, "Item On Click");
			}
		});
	}
	
	private ArrayList<ListViewObj> virtualList(){
		ArrayList<ListViewObj> result = new ArrayList<ListViewObj>();
		
		ListViewObj object;
		for(int i = 1; i < 500; i++){
			object = new ListViewObj();
			object.setName("Name " + i);
			object.setUrl("tomjerry (" + i + ").jpg");
			//object.setBitmap(null)
			
			result.add(object);
		}
		
		return result;
	}
}
